package com.dcy.oa.dao;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.dcy.common.base.dao.DcyBaseDao;
import com.dcy.common.model.PageModel;
import com.dcy.oa.mapper.LeaveMapper;
import com.dcy.oa.model.Leave;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author dcy
 * @since 2022-11-09
 */
@Service
public class LeaveDao extends DcyBaseDao<LeaveMapper, Leave> {

    /**
     * 获取表格数据
     *
     * @param leave
     * @param pageModel
     * @return
     */
    public IPage<Leave> pageListByEntity(Leave leave, PageModel pageModel) {
        LambdaQueryWrapper<Leave> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.eq(StrUtil.isNotBlank(leave.getUserId()), Leave::getUserId, leave.getUserId());
        queryWrapper.like(StrUtil.isNotBlank(leave.getName()), Leave::getName, leave.getName());
        queryWrapper.eq(StrUtil.isNotBlank(leave.getType()), Leave::getType, leave.getType());
        queryWrapper.between(leave.getBeginDate() != null && leave.getEndDate() != null, Leave::getLeaveDate, leave.getBeginDate(), leave.getEndDate());
        queryWrapper.orderByDesc(Leave::getLeaveDate);
        return pageList(pageModel, queryWrapper);
    }

}
